// Kony

#pragma once

#include "CoreMinimal.h"
#include "EnhancedInputComponent.h"
#include "BaseInputConfig.h"
#include "BaseInputComponent.generated.h"

/**
 * Enhanced 增强输入类
 */
UCLASS()
class GASC_HUANLING_API UBaseInputComponent : public UEnhancedInputComponent
{
	GENERATED_BODY()
public:
	//模板函数 必须用#include "BaseInputConfig.h" 引入而不能用class 前向声明
	//  PressedFuncType按下函数 , ReleasedFuncType释放函数 , HeldFuncType按住函数
	template<typename UserClass,typename PressedFuncType, typename ReleasedFuncType,typename HeldFuncType>
	void BindAbilityActions(const UBaseInputConfig* InputConfig,UserClass* Object,PressedFuncType PressedFunc,ReleasedFuncType ReleasedFunc,HeldFuncType HeldFunc);
	 
};

template <typename UserClass, typename PressedFuncType, typename ReleasedFuncType, typename HeldFuncType>
void UBaseInputComponent::BindAbilityActions(const UBaseInputConfig* InputConfig, UserClass* Object,PressedFuncType PressedFunc, ReleasedFuncType ReleasedFunc, HeldFuncType HeldFunc)
{
	check(InputConfig);
	for (const FBaseInputAction& Action : InputConfig->AbilityInputActions)
	{
		if (Action.InputAction && Action.InputTag.IsValid())
		{
			if (PressedFunc)
			{
				//绑定按键按下
				BindAction(Action.InputAction, ETriggerEvent::Started, Object, PressedFunc, Action.InputTag);
			}
			if (ReleasedFunc)
			{
				//绑定按键释放
				BindAction(Action.InputAction, ETriggerEvent::Completed, Object, ReleasedFunc, Action.InputTag);
			}
			if (HeldFunc)
			{
				//绑定按键按住
				BindAction(Action.InputAction,ETriggerEvent::Triggered, Object, HeldFunc, Action.InputTag);
			}
		}
	}
}
